<?php

namespace app\common\model;

use think\facade\Cache;
use think\Model;

/**
 * 用户维修
 */
class UserRepair extends BaseModel
{

    // 表名,不含前缀
    protected $name = 'user_repair';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = "datetime";
    // 定义时间戳字段名
    protected $updateTime = false;

    private function _decodeData($findData)
    {
        $findData['house'] = model('house')->selectById($findData['house_id'], true);
        $userInfo = model('user')->findById($findData['user_id']);
        $findData['user'] = [
            'id' => $userInfo['id'],
            'nickname' => $userInfo['nickname'],
            'phone' => $userInfo['phone'],
            'wx_avatar' => $userInfo['wx_avatar']
        ];
        return $findData;
    }

    public function house()
    {
        return $this->belongsTo("house", "house_id")->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo("user", "user_id")->setEagerlyType(0);
    }

    public function selectById($id)
    {
        $findData = $this->findById($id);
        return $this->_decodeData($findData);
    }

    public function getStatusList()
    {
        return [
            [
                "id" => 1,
                "title" => "未查阅"
            ],
            [
                "id" => 2,
                "title" => "已查阅"
            ],
        ];
    }

}
